from StringIO import StringIO
import gzip, urllib2
from BeautifulSoup import BeautifulSoup as bs

def get(a):
    r = urllib2.Request(a)
    r.add_header('Accept-encoding', 'gzip')
    r = urllib2.urlopen(r)
    if r.info().get('Content-Encoding') == 'gzip':
        r = gzip.GzipFile(fileobj=StringIO(r.read()))
    return r.read()


a = 'http://www.runoob.com/java/java-tutorial.html'

bs(str(bs(get(a)).find('div', attrs={'class': 'article-body'}))).find('h1').text